package com.netease.nie.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.netease.nie.base.controllers.BaseController;
import com.netease.nie.base.exceptions.BusinessException;
import com.netease.nie.base.protocol.SystemResponseCode;
import com.netease.nie.dto.ColumnGoodsSnapshotDto;
import com.netease.nie.dto.ExchangeGoodsInfoListDto;
import com.netease.nie.facade.ColumnGoodsFacade;

/**
 * 积分商城栏目商品接口
 * @author wwbn3695
 * @createDate June 30th,2016
 *
 */
@RestController
@RequestMapping("/api/column_goods")
public class ColumnGoodsController extends BaseController {
	
	@Autowired
	private ColumnGoodsFacade columnGoodsFacade;
	
	@RequestMapping(value = "/top_list", method = RequestMethod.GET, produces = "application/json")
	public String columnGoodsTopList(HttpServletRequest request, Integer page) throws Exception {
		Long userId = (Long) request.getAttribute("userId");
		
		if (page == null)
			page = 1;
		List<ColumnGoodsSnapshotDto> columnGoodsSnapshotDtos = columnGoodsFacade.listAllColumnGoodsSnapshotDto(userId, page);
		return jsonSuccess(columnGoodsSnapshotDtos);
	}
	
	
	@RequestMapping(value = "/more_list", method = RequestMethod.GET, produces = "application/json")
	public String columnGoodsMoreList(HttpServletRequest request, Integer id, Integer page) throws Exception {
		if (id == null)
			throw new BusinessException(SystemResponseCode.PARAM_KEY_ILLEGAL.getCode(), SystemResponseCode.PARAM_KEY_ILLEGAL.getMsg());
		
		if (page == null)
			page = 1;
		
		if (page <= 0)
			throw new BusinessException(SystemResponseCode.PARAM_VALUE_ILLEGAL.getCode(), SystemResponseCode.PARAM_VALUE_ILLEGAL.getMsg());
		
		Long userId = (Long) request.getAttribute("userId");
		
		List<ExchangeGoodsInfoListDto> exchangeGoodsInfoListDtos = columnGoodsFacade.listGoodsInfoDtoByColumnInfoId(id, page, userId);
		return jsonSuccess(exchangeGoodsInfoListDtos);
	}
}
